<?php
global $_GPC, $_W;
$GLOBALS['frames'] = $this->getMainMenu();
// var_dump($_GPC['class_id']);die;
$sql="SELECT a.*,b.cate_name FROM ".tablename('snx_teacher'). " a"  . " left join " . tablename("snx_school") . " b on a.school_id=b.id where a.id={$_GPC['id']}";
$info=pdo_fetch($sql);
 // $info = pdo_get('snx_teacher',array('id'=>$_GPC['id']));
  $classid = $info['class_id'];
  $class = pdo_fetchall("select class_name from" .tablename('snx_class') . "where id in($classid)");
      $datas=pdo_fetchall("select * from" .tablename('snx_teacher') . "where id not in(select id from ims_snx_teacher where id={$_GPC['id']})");
      // var_dump($datas);die;
      $list = pdo_getall('snx_teacher',array('uniacid'=>$_W['uniacid']),array('class_id'));
      $list = array_column($datas, 'class_id');
      // var_dump($list);die;
      $list = implode(',', $list);
      foreach ($_GPC['class_id'] as $value) {
        if (strstr($list,$value)) {
           message('该班级已有老师存在','','error');
        }
      }
  if(checksubmit('submit')){
    if (empty($_GPC['username'])) {
       message('用户名不能为空','','error');
   }if(empty($_GPC['teacher_name'])){
       message('老师名称不能为空','','error');
   }if(empty($_GPC['password'])){
       message('密码不能为空','','error');
   }if ($_GPC['password'] != $_GPC['repassword']){
       message('两次输入的密码不一致','','error');
   }
  $data['username']=$_GPC['username'];
         $data['c_id']=$_GPC['course_name'];
         $data['cou_id']=$_GPC['name'];
  $data['teacher_name']=$_GPC['teacher_name'];
  $data['password']=md5(md5($_GPC['password']));
  $data['state']=$_GPC['state'];
         $data['school_id']=$_GPC['cate_name'];
  $data['class_id']=implode(",", $_GPC['class_id']);
  $res = pdo_update('snx_teacher',$data,array('id'=>$_GPC['id']));     
  if($res){
    message('修改成功',$this->createWebUrl('teacher',array()),'success');
  }else{
    message('修改失败','','error');
  }  
} 


include $this->template('web/editteacher');